<!DOCTYPE html>
[#assign ctx=springMacroRequestContext.contextPath/]
<html>
<head>
  <meta charset="utf-8">
  <title>我的产品</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${ctx!}/statics/layui/css/layui.css" media="all">
  <script type="text/javascript" src="${ctx}/statics/layui/layui.js"></script>
  <script src="${ctx}/statics/js/jquery-3.6.0.js"></script>
  <script src="${ctx}/statics/js/xadmin.js"></script>
</head>
<body>

<div class="layui-layout layui-layout-admin">

  [#include "/common/headNav.html"]
  [#include "/common/sideNav.html"]


  <div class="layui-body">
    <!-- 内容主体区域 -->

    <!-- 表格 -->
    <table class="layui-hide" id="table" lay-filter="table"></table>
  </div>

<!--  <div class="layui-footer">-->
    <!-- 底部固定区域 -->
  </div>
</div>



<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">买入</a>
  <a class="layui-btn layui-btn-xs" lay-event="sell">卖出</a>
</script>


<script>

  layui.use('form',function () {
    var form = layui.form;

    //监听提交
    form.on('submit(demo1)', function(data){
      layer.alert(JSON.stringify(data.field), {
        title: '最终的提交信息'
      })
      return false;
    });
  })

  layui.use('table', function(){
    var table = layui.table;

    table.render({
      elem: '#table'
      ,url:'/userProduct/list'
      ,page: true
      ,limit :15
      ,limits :[15,30,60]
      ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
      ,parseData:function (res){
        return{
          "code":res.code,
          "msg":res.msg,
          "count":res.count,
          "data":res.data
        };
      }
      ,cols: [[
        {field:'productCode', width:'20%', title: '产品编号'}
        ,{field:'productName',  width:'20%', title: '产品名称'}
        ,{field:'amount',  width:'20%', title: '持有份额'}
        ,{field:'value',  width:'20%', title: '金额'}
        ,{field:'operate',  width:'20%', title: '操作',toolbar: '#barDemo'}
      ]]
    });


    //监听行工具事件
    table.on('tool(table)', function(obj){
      var code = obj.data.productCode;
      var amount = obj.data.amount;
      //console.log(obj)
      if(obj.event === 'edit'){
        var tempwindow = window.open('_blank');
        tempwindow.location = "${ctx}/productDetail/index?code="+code;
      }
      if(obj.event === 'sell'){

        xadmin.open('产品出售','/userProduct/sellConfirm?code='+code+"&maxAmount="+amount,500,150)
      }
    });
  });




</script>

</body>
</html>